<style lang="less">
  .order-entering-sty {
    .el-row {
      margin-bottom: 20px;
    }

    .el-col {
      border-radius: 4px;
    }

    .bg-purple-dark {
      background: #ffffff;
    }

    .grid-content {
      border-radius: 4px;
      min-height: 36px;
    }

    .el-form-item {
      margin: 0px 20px 15px 20px;
    }

    .f-bs1 {
      border: 1px solid #dfe6ec;
    }

    .f-bsr1 {
      border-right: 1px solid #dfe6ec;
      border-radius: 0;
    }

    .f-bl1 {
      border-left: 1px solid #dfe6ec;
    }

    .f-bsb1 {
      border-bottom: 1px solid #dfe6ec;
      border-right: 1px solid #dfe6ec;
      border-left: 1px solid #dfe6ec;
    }

    .f-bcc {
      background-color: #bedbf7;
    }

    .f-tc {
      text-align: center;
    }

    .el-collapse {
      border: 0px;
      .el-collapse-item {
        border: 1px solid #dfe6ec;
        margin-bottom: 10px;
        .el-collapse-item__header {
          font-weight: bold;
          .el-collapse-item__header__arrow {
            display: none;
          }
        }
        .el-collapse-item__content {
          padding-bottom: 0px;
        }
        .el-collapse-item__wrap {
          border-bottom: 0px;
          .el-collapse-item__content {
            padding: 0px 0px;
          }
        }
      }
      .ecl-um-sy {
        .el-collapse-item__wrap {
          height: 48px;
        }
      }
      .eci-time-sty {
        .el-collapse-item__wrap {
          height: 100px;
          .el-collapse-item__content {
            height: 100px;
          }
        }
      }
    }

    label {
      width: 100px;
    }

    .el-form-item[data-v-7da61f17] {
      margin: 0 0 0 0
    }

    .f-mt10 {
      margin-top: 10px;
    }

    .f-ml20 {
      margin-left: 20px;
    }

    .f-mr20 {
      margin-right: 20px;
    }

    .f-mb10 {
      margin-bottom: 10px;
    }

    .f-tar {
      text-align: right;
    }

    .f-h30 {
      height: 30px;
    }

    .el-input .el-input__inner {
      height: 22px;
    }
    .f-c-red {
      color: red;
    }

    .el-radio-group {
      width: 60%;
    }

    .el-radio-invoice {
      margin-right: 30px;
    }

    .f-color {
      color: #25baaf;
    }

    .el-textarea {
      width: 86%;
    }

    .f-mb {
      margin-bottom: 0;
    }

    .f-fr {
      float: right;
    }

    .f-fl {
      float: left;
    }

    .f-lh38 {
      line-height: 38px;
    }

    .el-select {
      width: 100%;
    }

    .f-w233 {
      width: 100%;
    }
    .f-w130 {
      width: 135%;
    }

    .el-form-item__label {
      width: 150px;
    }

    .el-date-editor.el-input {
      width: 100%;
    }

    li {
      list-style-type: none;
    }

    .color-c8c8c8 {
      color: #c8c8c8;
    }

    .f-mt {
      margin-top: 0;
    }
    .el-collapse-item__header {
      height: 40px;
      line-height: 40px;
    }

    .el-form-item {
      margin: 0px 0px 15px 20px;
    }
    .el-col-4 {
      width: 18%;
    }
    .efi-cargo-sty {
      .el-form-item__content {
        line-height: 0px;
        margin-top: 3px;
      }
    }
    .el-input {
      height: 22px;
    }
    .el-input__icon {
      margin-top: 7px;
    }
    .el-form-item__error {
      /*padding-top: 23px;*/
      top: 24px;
    }
  }
</style>
<template>
  <div class="order-entering-sty">
    <el-row>
      <el-col :span="24">
        <div class="f-bs1 grid-content bg-purple-dark">
          <div class="f-fl f-lh38 f-ml20">
            订单编号：<label>{{orderForm.orderNumber}}&nbsp;&nbsp;</label><label>{{orderForm.orderSourceName}}&nbsp;&nbsp;</label><label>{{orderForm.orderStatusName}}</label>
          </div>
          <div class="f-fr f-lh38 f-mr20">
            <label>{{this.$store.state.username}}&nbsp;&nbsp;</label><label>{{orderForm.organizationModel.name}}&nbsp;&nbsp;</label><label>{{orderForm.createDate}}&nbsp;&nbsp;</label>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-form ref="orderForm" label-position="right" label-width="39%" :model="orderForm" :rules="rules">
      <el-collapse v-model="activeNames">
        <el-collapse-item title="客户" name="1" class="ecl-um-sy">
          <el-row class="f-mb10">
            <el-col :span="4">
              <el-form-item label="客户名称" prop="memberUserId">
                <el-input :disabled="true" v-model="realName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="货运单号" prop="freightNumber">
                <el-input size="mini" v-model="orderForm.freightNumber" placeholder="请输入货运单号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="运单号" prop="transportationNumber">
                <el-input v-model="orderForm.transportationNumber" placeholder="请输入运单号"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item name="3" class="ecl-um-sy">
          <template slot="title">
            发货地址
            <el-button v-if="orderForm.memberUserId !==''" @click="addContacts({type:109002002,name:'发货地址'})">
              添加发货联系人
            </el-button>
          </template>
          <el-row>
            <el-col :span="4">
              <el-form-item label="发货人" prop="shipmentsContactName">
                <el-select v-model="orderForm.shipmentsContactName"
                           remote
                           :remote-method="sshipmentAddresses"
                           filterable
                           clearable
                           placeholder="请选择发货人"
                           @change="shipmentsContactNameChange">
                  <el-option v-for="(shipmentAddress,index) in shipmentAddresses"
                             :label="shipmentAddress.contactName"
                             :value="shipmentAddress.id" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="手机号码" prop="shipmentsContactPhone">
                <el-input v-model="orderForm.shipmentsContactPhone" placeholder="请输入手机号码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="固定电话" prop="shipmentTelephone">
                <el-input v-model="orderForm.shipmentsTelephone" placeholder="请输入固定电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="所在地" prop="shipmentAddressesSelect">
                <address-select v-model="orderForm.shipmentAddressesSelect"
                                @change="sendAddressSelectChange('shipmentAddress')"
                                placeholder="请选择地址"
                                class="f-w130"></address-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="街道" prop="shipmentsStreet">
                <el-input v-model="orderForm.shipmentsStreet" class="f-w130" placeholder="请输入街道"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item name="4" class="ecl-um-sy">
          <template slot="title">
            收货地址
            <el-button v-if="orderForm.memberUserId !==''" @click="addContacts({type:109002001,name:'收货地址'})">
              添加收货联系人
            </el-button>
          </template>
          <el-row>
            <el-col :span="4">
              <el-form-item label="收货人" prop="sendContactName">
                <el-select v-model="orderForm.sendContactName"
                           remote
                           :remote-method="ssendAddresses"
                           filterable clearable placeholder="请选择收货人"
                           @change="sendContactNameChange">
                  <el-option v-for="(sendAddress,index) in sendAddresses"
                             :label="sendAddress.contactName"
                             :value="sendAddress.id" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="手机号码" prop="sendContactPhone">
                <el-input v-model="orderForm.sendContactPhone" placeholder="请输入手机号码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="固定电话" prop="sendTelephone">
                <el-input v-model="orderForm.sendTelephone" placeholder="请输入固定电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="所在地" prop="sendAddressSelect">
                <address-select v-model="orderForm.sendAddressSelect"
                                @change="sendAddressSelectChange('sendAddress')" placeholder="请选择地址"
                                class="f-w130"></address-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="街道" prop="sendStreet">
                <el-input v-model="orderForm.sendStreet" class="f-w130" placeholder="请输入街道"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="计划时间" name="2" class="eci-time-sty">
          <el-row style="margin-bottom: 0px">
            <el-col :span="4">
              <el-form-item class="f-mb" label="发货日期" prop="shipmentsDate">
                <div class="block f-h30" v-if="lineType !== 112006004">
                  <ue-el-date-picker v-model="orderForm.shipmentsDate" @change="calculatePrice"
                                     :picker-options="shipmentsDateValuePOS"></ue-el-date-picker>
                  <!--<div style="float: left">-->
                  <!--<label style="float: left;width: auto">提前发运享受优惠: </label>-->
                  <label class="f-c-red" style="float: left;width: 30px;display: none"
                         v-html="discountText"></label>
                  <!--</div>-->
                </div>
                <div class="block f-h30" v-if="this.lineType===112006004">
                  <ue-el-date-picker v-model="orderForm.shipmentsDate"
                                     :picker-options="extractTimeValuePOS"></ue-el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="提货方式" prop="extractType">
                <el-select v-model="orderForm.extractType" @visible-change="searchextractTypes(105002)"
                           @change="searchextractTypeChange"
                           filterable placeholder="请选择提货方式">
                  <el-option v-for="(et,index) in extractTypes" :label="et.cnDictValname"
                             :value="et.dictVal" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="提货网点" v-if="orderForm.extractType===105002002" prop="startNetworkManagementId">
                <el-select v-model="orderForm.startNetworkManagementId"
                           filterable
                           placeholder="请选择提货网点">
                  <el-option v-for="(enm,index) in startNetworkManagements"
                             :label="enm.netWorkName+' | '+enm.netWorkAddressNames+enm.street"
                             :value="enm.id" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="f-mb" label="计划提货日期" prop="extractDate" v-if="orderForm.extractType===105002001"
                            :rules="[ {required: true,type:'date', message: '请选择计划提货日期', trigger: 'blur'},
                            { validator:this.extractDateFun}]">
                <div class="block f-h30">
                  <el-date-picker :disabled="orderForm.extractType === 105002002" format="yyyy-MM-dd"
                                  v-model="orderForm.extractDate" type="date" placeholder="选择计划提货日期"></el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="计划提货时间" prop="extractTime" v-if="orderForm.extractType===105002001"
                            :rules="[ {required: true, message: '请选择计划提货时间', trigger: 'blur'}]">
                <el-select :disabled="orderForm.extractType === 105002002"
                           v-model="orderForm.extractTime"
                           filterable placeholder="请选择计划提货时间">
                  <el-option v-for="(extractTime,index) in extractTimes" :label="extractTime.cnDictValname"
                             :value="extractTime.dictVal" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row style="margin-bottom: 0px">
            <el-col :span="4">
              <el-form-item label="">
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="送货方式" prop="sendType">
                <el-select v-model="orderForm.sendType" @visible-change="searchextractTypes(105001)"
                           filterable
                           @change="sendTypeTypeChange"
                           placeholder="请选择送货方式">
                  <el-option v-for="(sendType,index) in sendTypes" :label="sendType.cnDictValname"
                             :value="sendType.dictVal" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="送货网点" v-if="orderForm.sendType===105001002" prop="endNetworkManagementId">
                <el-select v-model="orderForm.endNetworkManagementId"
                           filterable
                           placeholder="请选择送货网点">
                  <el-option v-for="(snm,index) in endNetworkManagements"
                             :label="snm.netWorkName+' | '+snm.netWorkAddressNames+snm.street"
                             :value="snm.id" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item style="margin-bottom: 0px" label="计划送货时间" prop="sendTime" class="efi-cargo-sty"
                            v-if="orderForm.sendType===105001001">
                <div class="block f-h30">
                  <el-date-picker :disabled="orderForm.sendType === 105001002"
                                  v-model="orderForm.sendTime" type="date" placeholder="选择计划送货时间"
                                  :picker-options="sendTimeValuePOS"></el-date-picker>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-form ref="orderCargoForm" label-position="right" label-width="100px" :model="orderCargoForm"
                 :rules="orderCargoFormRules">
          <el-collapse v-model="activeNames">
            <el-collapse-item title="货物信息" name="5">
              <el-row style="margin-bottom: 0px">
                <el-col :span="4">
                  <el-form-item label="货物品名" class="efi-cargo-sty" prop="cargoId">
                    <el-select v-if="!isCargoShow" v-model="orderCargoForm.cargoId"
                               clearable
                               placeholder="请选择货物品名" @change="cargoNameChange">
                      <el-option v-for="(cargoModel,index) in cargoNames" :label="cargoModel.name"
                                 :value-key="cargoModel.id"
                                 :value="cargoModel.id" :key="index"></el-option>
                    </el-select>
                    <el-input v-if="isCargoShow" v-model="orderCargoForm.cargoName"
                              placeholder="请输入货物品名"></el-input>
                    <el-button type="text" class="f-fr" style="position: relative;padding: 0px 0px"
                               @click="elseCargoClick">{{isCargoShowText}}
                    </el-button>
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item label="货物类型" class="efi-cargo-sty" prop="cargoTypeName">
                    <el-input :disabled="true" v-model="orderCargoForm.cargoTypeName"
                              placeholder="货物类型"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item label="货物包装" class="efi-cargo-sty" prop="packType">
                    <el-select v-if="!isPackTypeShow" v-model="orderCargoForm.packType"
                               @change="packTypeChanges"
                               @visible-change="searchPackTypes"
                               filterable placeholder="请选择货物包装">
                      <el-option v-for="(packType,index) in packTypes" :label="packType.cnDictValname"
                                 :value="packType.dictVal" :key="index"></el-option>
                    </el-select>
                    <el-input v-if="isPackTypeShow" v-model="orderCargoForm.packTypeName"
                              placeholder="请输入货物包装"></el-input>
                    <el-button type="text" class="f-fr" style="position: relative;padding: 0px 0px"
                               @click="elsePackTypeClick">{{isPackTypeShowText}}
                    </el-button>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="货物备注" prop="remark">
                    <el-input autosize type="textarea" v-model="orderCargoForm.remark"
                              placeholder="请输入货物备注"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-bottom: 0px">
                <el-col :span="4">
                  <el-form-item label="重量（吨）" class="efi-cargo-sty" prop="weight">
                    <el-input type="number" step="0.01" v-model="orderCargoForm.weight"
                              @blur="changeVolumeAndWeight"
                              placeholder="请输入重量"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item label="体积（方）" class="efi-cargo-sty" prop="volume">
                    <el-input type="number" step="0.01" v-model="orderCargoForm.volume"
                              @blur="changeVolumeAndWeight"
                              placeholder="请输入体积"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item label="件数" class="efi-cargo-sty" prop="amount">
                    <el-input type="number" v-model.number="orderCargoForm.amount"
                              placeholder="请输入件数"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-bottom: 0px" v-if="isHeavyRatioInterval||iszp">
                <el-col :span="15">
                  <el-form-item label="重泡比提示">
                    <el-input :disabled="true" v-model="mStmHeavyRatioInterval.promptCopy"
                              placeholder="请输入件数"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-collapse-item>
          </el-collapse>
        </el-form>
        <el-collapse-item name="6" class="ecl-um-sy">
          <template slot="title" class="ecl-um-sy">
            <div>
              <el-col :span="1">增值服务</el-col>
              <el-col :span="2">
                <el-form-item label="等通知放货" label-width="100px" style="margin-bottom: 0px">
                  <el-checkbox style="width: auto" v-model="noticeDelivery"></el-checkbox>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-tooltip placement="top">
                  <div slot="content">发货人委托平台把货物发送到目的地，货物到达目的地之后，平台必须先收到发货人的通知，方可将货物移交(送达)给收货人。
                    发货人需在3天内确认放货，若超过3天未通知放货，平台将按货量和天数，收取一定的仓储费。
                  </div>
                  <el-button type="text"><i class="f-color fa fa-info-circle" aria-hidden="true"></i></el-button>
                </el-tooltip>
              </el-col>
            </div>
          </template>
          <el-row>
            <el-col :span="4">
              <el-form-item label="保价声明">
                <el-input type="number" step="0.01" @blur="addValueChange('bj')"
                          v-model.number="addValues[0].value"
                          placeholder="请输入保价声明">
                  <template slot="append">
                    <el-tooltip placement="top">
                      <div slot="content" v-html="supportRateHtml"></div>
                      <el-button type="text"><i class="f-color fa fa-info-circle" aria-hidden="true"></i>
                      </el-button>
                    </el-tooltip>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="代收金额">
                <el-input type="number" size="mini" step="0.01" @blur="addValueChange('ds')"
                          v-model.number="addValues[1].value"
                          placeholder="请输入代收金额">
                  <template slot="append">
                    <el-tooltip placement="top">
                      <div slot="content">贷款金额大于0且不高于5万代收货款率0.3%</div>
                      <el-button type="text"><i class="f-color fa fa-info-circle" aria-hidden="true"></i></el-button>
                    </el-tooltip>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="回单类型" prop="receiptType">
                <el-select :disabled="hdds" v-model="receiptType"
                           @change="searchReceiptTypeChange"
                           placeholder="请选择回单类型">
                  <el-option label="电子回单" value="101002003"></el-option>
                  <el-option label="原件回单" value="101002004"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="发票类型" prop="invoiceType">
                <el-select :disabled="inds" v-model="invoiceTypeModel" clearable
                           @change="invoiceTypeChange"
                           placeholder="请选择发票类型">
                  <el-option label="个人普通发票" value="101002005"></el-option>
                  <el-option label="单位普通发票" value="101002006"></el-option>
                  <el-option label="企业专用发票" value="101002007"></el-option>
                  <template slot="append">
                    <el-tooltip placement="top">
                      <div slot="content">普通发票税率 3%</div>
                      <el-button type="text"><i class="f-color fa fa-info-circle" aria-hidden="true"></i>
                        发 &nbsp; &nbsp; 票
                      </el-button>
                    </el-tooltip>
                  </template>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="发票抬头">
                <el-input v-if="orderForm.agingDictEntityId === 112006004" :disabled="fbtitleds"
                          v-model="orderForm.valueMessage"
                          placeholder="请输入发票抬头"></el-input>
                <el-select v-if="orderForm.agingDictEntityId !== 112006004"
                           v-model="taxsheetTitle"
                           remote
                           :remote-method="searchTaxsheetTitleRm"
                           @change="searchTaxsheetTitleChange"
                           filterable
                           placeholder="请选择发票抬头">
                  <el-option v-for="(tht,index) in taxsheetTitles" :label="tht.taxsheetTitle"
                             :value="tht.id" :key="index">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="运输产品" name="7" property="agingId">
          <el-row class="f-ml10">
            <el-radio-group v-if="lineType !== 111002004" v-model="orderForm.agingModel" prop="agingId"
                            @change="bfcalculatePrice">
              <div v-for="(shipping,index) in shippings" class="f-mt10" :key="index">
                <el-radio class="radio" :label="shipping">
                  {{shipping.ageingTypeName}}
                  <label v-if="shipping.ageingType!==112006003&&shipping.ageingType!==112006004"
                         class="f-ml20">{{shipping.remark}}</label>
                  <label v-if="shipping.ageingType!==112006003&&shipping.ageingType!==112006004"
                         class="f-ml20 f-color">预计{{shipping.ageingScope}}到达，起步运费{{shipping.startToll}}，重货{{shipping.heavyStartToll}}元/吨（起），轻货{{shipping.gentlyStartToll}}元/方（起）
                  </label>
                  <label class="f-ml20" v-if="orderForm.agingModel.ageingType === 112006003">
                    <el-input type="number"
                              v-if="shipping.ageingType===112006003" v-model="freightPrice"
                              @change="pricing" style="margin-left: 20px;width: 150px"
                              placeholder="请输入价格"></el-input>
                    <el-input type="number"
                              v-if="shipping.ageingType===112006003" v-model="freightMsgPrice"
                              @change="pricing"
                              style="margin-left: 20px;width: 150px"
                              placeholder="请输入信息服务"></el-input>
                  </label>
                </el-radio>
              </div>
            </el-radio-group>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="付款方式" name="8">
          <el-row class="f-ml10">
            <el-radio-group v-model="orderForm.paymentType" @change="calculatePrice">
              <el-radio v-for="(py,index) in paymentTypes" class="radio" :label="py.payWay" :key="index">
                {{py.payWayName}}
              </el-radio>
            </el-radio-group>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="订单备注" name="9">
          <el-row>
            <el-col :span="4">
              <el-form-item label="订单备注" prop="remark">
                <el-input type="textarea" style="width: 300%;margin-top: 3px" v-model="orderForm.remark"
                          placeholder="请输入订单备注"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="费用详情" name="10">
          <el-row style="width: 100%;margin: auto" class="f-bs1">
            <el-col :span="6" class="f-bsr1 f-tc f-bcc">
              <div class="grid-content">短途提货费
                <label class="grid-content f-text-red f-fr" v-html="duthf"></label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bl1 f-bcc">
              <div class="grid-content">保价运费
                <label class="grid-content f-text-red f-fr" v-html="bjyf"></label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bcc">
              <div class="grid-content">干线运费
                <label class="f-text-red f-fr" style="width: auto" v-html="gxyf">
                </label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bl1 f-bcc">
              <div class="grid-content">代收货款费
                <label class="grid-content f-text-red f-fr" v-html="dshkf"></label>
              </div>
            </el-col>
          </el-row>
          <el-row style="width: 100%;margin: auto" class="f-bsb1">
            <el-col :span="6" class="f-bsr1 f-tc f-bcc">
              <div class="grid-content">短途送货费
                <label class="grid-content f-text-red f-fr" v-html="dtshf"></label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bcc" v-if="orderForm.agingDictEntityId===112006003">
              <div class="grid-content">信息费
                <label v-if="orderForm.agingDictEntityId===112006003" class="grid-content f-text-red f-fr"
                       v-html="xxf"></label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bcc" v-if="orderForm.agingDictEntityId!==112006003">
              <div class="grid-content">月结费
                <label v-if="orderForm.agingDictEntityId!==112006003" class="grid-content f-text-red f-fr"
                       v-html="yjf"></label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bl1 f-bcc">
              <div class="grid-content">回单费
                <label class="grid-content f-text-red f-fr" v-html="hdf"></label>
              </div>
            </el-col>
            <el-col :span="6" class="f-bsr1 f-tc f-bl1 f-bcc">
              <div class="grid-content">发票费
                <label class="grid-content f-text-red f-fr" v-html="fpf"></label>
              </div>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
      <div class="f-tar f-mt10 f-mb10">
        <div class="f-tar f-mt10 f-mb10">
          <el-button type="primary" @click="calculatePrice">预估费用</el-button>
        </div>
        <li class="f-mt10">订单金额：{{Math.round(orderForm.orderPrice * 100) / 100}} 元
        </li>
      </div>
      <div class="f-tar f-mt10 f-mb10">
        <el-button type="danger" @click="resetOrderForm('reset')">新增</el-button>
        <el-button type="primary" @click="createOrder(101001001,'save')">保存</el-button>
        <el-button type="primary" @click="createOrder(101001001,'saveAndReset')">保存&新增</el-button>
        <el-button type="primary" @click="createOrder(101001002,'saveAndReset')">保存&提交</el-button>
      </div>
    </el-form>
    <el-dialog :title="addressDialogTitle" size="tiny" :visible.sync="addressDialog">
      <el-form :model="myAddress" label-width="130px" ref="myAddress">
        <el-form-item label="地址类型" style="height: 55px">
          <el-input :disabled="true" v-model="myAddress.addressTypeName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="contactName" style="height: 55px"
                      :rules="[{required: true,  message: '姓名不能为空', trigger: 'change'}]">
          <el-input v-model="myAddress.contactName"
                    placeholder="请输入真实姓名"></el-input>
        </el-form-item>
        <el-form-item label="手机" prop="contactPhone" style="height: 55px"
                      :rules="[{trigger: 'change',validator:this.phoneFun}]">
          <el-input type="number" v-model="myAddress.contactPhone"
                    placeholder="请输入手机号码"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="telephone" style="height: 55px"
                      :rules="[{trigger: 'change',validator:this.phoneFun}]">
          <el-input type="number" v-model="myAddress.telephone"
                    placeholder="请输入固定电话"></el-input>
        </el-form-item>
        <el-form-item label="通信地址" prop="addressSelect" style="height: 55px"
                      :rules="[{required: true,type:'array', message: '通信地址不能为空', trigger: 'change'}]">
          <address-select v-model="myAddress.addressSelect"
                           placeholder="请选择地址"
                          class="f-w233"></address-select>
        </el-form-item>
        <el-form-item prop="street">
          <el-input auto-complete="off" v-model="myAddress.street" placeholder="街道-路-门牌号"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addressDialog = false">取消</el-button>
        <el-button type="primary" @click="addAddress">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getMemberUsers, searchDictEntitys, saveAddress } from '../../api/customer/maintain.js';
import { getStmParamByType } from '../../api/system/stmParam.js';
import { getFreightAddValue, searchReservationRuleFreights } from '../../api/freight/freightApi.js';
import { getDictEntityByDictCode, getDictEntity } from '../../api/system/Dict.js';
import { getItemNames } from '../../api/system/ItemName.js';
import { getAddresses } from '../../api/address/address.js';
import { saveOrder, searchLine, searchPrice } from '../../api/order/order.js';
import { searchInvoiceManageByFilters } from '../../api/meb-user/TaxsheetTitle.js';
import { isEmpty, getSelectObect } from '../../lib/util.js';
import { getStmHeavyRatio } from '../../api/system/StmHeavyRatio.js';
import { search } from '../../api/basedata/networkManagementApi.js';
import { searchALLPayWayConfig } from '../../api/system/PayWayConfig.js';

export default {
  data () {
    return {
      token: this.$store.state.token,
      userId: this.$store.state.userId,
      realName: JSON.parse(sessionStorage.getItem('user')).realName,
      radio: '',
      startNetworkManagements: [],
      endNetworkManagements: [],
      isCargoShow: false,
      isPackTypeShow: false,
      isCargoShowText: '手输',
      isPackTypeShowText: '手输',
      isTaxsheetTitlesDefault: false,
      addValueDatav2: [],
      taxsheetTitles: [],
      taxsheetTitle: '',
      addressDialogTitle: '',
      addressDialog: false,
      addressSelect: [], // 每个页面用完要清空
      receiptType: '101002003',
      paymentTypes: [],
      lineType: '',
      freightContract: {},
      freightPrice: '',
      freightMsgPrice: '',
      memberUsers: [],
      extractTypes: [],
      sendTypes: [],
      shipmentAddresses: [],
      shipmentAddressesSelectModel: [], // 发货地址备用model
      sendAddressSelectModel: [], // 收货地址备用model
      shipmentAddressesSelectid: '', // 发货地址备用id
      sendAddressSelectId: '', // 收货地址备用id
      sendAddresses: [],
      invoiceAddressSelect: [],
      cargoNames: [],
      packTypes: [],
      invoiceTypes: [],
      receiptTypes: [],
      shippings: [],
      extractTimes: [{
        cnDictValname: '08:30-11:30',
        dictVal: '08:30-11:30'
      }, {
        cnDictValname: '13:30-18:00',
        dictVal: '13:30-18:00'
      }, {
        cnDictValname: '19:30-22:00',
        dictVal: '19:30-22:00'
      }],
      cnDictValname: '',
      send_contactPhone: '',
      send_telephone: '',
      send_street: '',
      shipment_contactPhone: '',
      shipment_telephone: '',
      shipment_street: '',
      cargoTypeName: '',
      shipmentsDateValuePOS: {
        discount: {},
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      extractTimeValuePOS: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      sendTimeValuePOS: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      shipmentsDateValue: '',
      extractTimeValue: '',
      activeNames: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
      orderCargoFormRules: {
        cargoId: [
          {required: true, trigger: 'change', validator: this.checkCargo}
        ],
        weight: [
          {min: 0.01, max: 10000, message: '货品重量在0-10000吨以内'}
        ],
        volume: [
          {min: 0.01, max: 10000, message: '货品体积在0-10000方以内'}
        ],
        amount: [
          {required: true, message: '请输入货品件数'},
          {type: 'integer', min: 1, max: 100000, message: '货品件数数量请控制在100000以内'}
        ],
        agingId: [
          {required: true, message: '请选择服务产品', trigger: 'blur'}
        ]
      },
      rules: {
        shipmentsDate: [
          {type: 'date', required: true, message: '请输入发货日期', trigger: 'blur'}
        ],
        extractType: [
          {required: true, type: 'number', message: '请输入提货方式', trigger: 'change'}
        ],
        sendType: [
          {required: true, type: 'number', message: '请输入送货方式', trigger: 'change'}
        ],
        shipmentsContactName: [
          {required: true, message: '请输入发货人', trigger: 'blur'}
        ],
        shipmentAddress: [
          {required: true, message: '请输入发货人地址', trigger: 'blur'}
        ],
        shipmentAddressesSelect: [
          {required: true, type: 'array', message: '请输入发货人省市区', trigger: 'blur'}
        ],
        sendContactName: [
          {required: true, message: '请输入收货人', trigger: 'blur'}
        ],
        sendAddress: [
          {required: true, message: '请输入收货人地址', trigger: 'blur'}
        ],
        sendAddressSelect: [
          {required: true, type: 'array', message: '请输入收货人省市区', trigger: 'blur'}
        ]
      },
      orderCargoForm: {
        cargoTypeName: '',
        cargoModel: '',
        cargoName: '',
        cargoId: '',
        cargoType: '',
        packType: '',
        packTypeName: '',
        weight: '',
        volume: '',
        amount: '',
        remark: ''
      },
      receiptTypeModel: '', // 回单
      invoiceTypeModel: '', // 发票
      valueMessageqw: '', // 发票抬头
      noticeDelivery: false, // 等通知放货
      addValues: [
        {
          dictValue: '101002001', // 保价声明
          value: '30000',
          remark: ''
        },
        {
          dictValue: '101002002', // 货代金额
          value: '',
          remark: ''
        },
        {
          dictValue: '', // 回单类型
          value: '',
          remark: ''
        },
        {
          dictValue: '', // 发票类型
          value: '',
          remark: '',
          taxsheetTitleId: '',
          taxsheetTitle: ''
        }],
      orderForm: {
        valueMessage: '',
        orderNumber: '', // 订单编号
        orderSourceName: '', // 订单来源
        orderStatusName: '', // 订单状态名称
        createDate: '', // 录入时间
        receiptType: 101002003, // 录入时间
        mMebPersonal: {
          partnerName: ''
        },
        organizationModel: {
          name: ''
        },
        orderStatusModel: {
          cnDictValname: ''
        },
        agingDictEntityId: '', // 时效字典id
        preferentialLine: '', // 优惠线路
        advanceOrder: '', // 提前下单
        memberUserId: '',
        memberUserName: '',
        memberUser: '',
        freightNumber: '', // 货运单号
        transportationNumber: '', // 运单号
        shipmentsDate: '', // 发货时间
        extractType: '', // 提货方式
        extractDate: '',
        extractTime: '',
        sendType: '', // 送货类型
        orderPrice: '', // 订单总金额
        sendTime: '',
        shipmentsAddressId: '', // 发货地址
        shipmentAddressesSelect: [], // 发货地址数组
        shipmentsProvince: '', // 发货-省
        shipmentsProvinceId: '', // 发货-省id
        shipmentsCity: '', // 发货-市
        shipmentsCityId: '', // 发货-市id
        shipmentsCounty: '', // 发货-县
        shipmentsCountyId: '', // 发货-县id
        shipmentsContactName: '',
        shipmentsContactPhone: '',
        shipmentsTelephone: '',
        shipmentsAddress: '',
        shipmentsStreet: '',
        sendAddressSelect: [], // 收货地址数组
        sendAddressId: '', // 收货地址
        sendProvince: '', // 收货-省
        sendProvinceId: '', // 收货-省id
        sendCity: '', // 收货-市
        sendCityId: '', // 收货-市id
        sendCounty: '', // 收货-县
        sendCountyId: '', // 收货-县id
        sendContactName: '',
        sendContactPhone: '',
        sendTelephone: '',
        sendAddress: '',
        sendStreet: '',
        orderCargos: [], // 货物信息
        addValues: [], // 增值服务
        paymentType: '', // 付款方式
        orderStatus: '', // 订单状态
        agingModel: '', // 时效方式model
        agingId: '', // 时效方式
        agingName: '', // 时效方式名称
        orderCostDetails: [], // 订单费用明细
        invoiceAddressId: '', // 发票地址id
        invoiceAddress: '', // 发票地址id
        invoiceAddressProvince: '', // 发票省
        invoiceAddressProvinceId: '', // 发票省id
        invoiceAddressCity: '', // 发票市
        invoiceAddressCityId: '', // 发票市id
        invoiceAddressCounty: '', // 发票县
        invoiceAddressCountyId: '', // 发票县id
        invoiceAddressStreet: '', // 发票地址街道
        startNetworkManagementId: '', // 自送
        endNetworkManagementId: '', // 自提
        remark: ''
      },
      orderPrice: {
        grossfreight: '', // 总运费
        shortHaul: '', // 短途提货费
        trunkFreight: '', // 干线运费
        shortDeliveryCharge: '', // 短途送货费
        monthlyFee: '', // 月结费
        insured: '', // 保价
        collection: '', // 代收货款
        theReceipt: '', // 回单
        invoice: '', // 发票
        remark: '', // 备注
        costDetailTotal: ''// 费用明细的总和
      },
      orderPrices: [],
      sxType: '', // 时效方式
      inds: false, //
      hdds: false, //
      fbtitleds: false, //
      discount: '',
      myAddress: {
        id: null,
        addressId: null,
        addressIds: null,
        userId: '',
        contactName: null,
        contactPhone: null,
        telephone: null,
        street: null,
        country: null,
        province: null,
        provinceId: null,
        city: null,
        cityId: null,
        options: [],
        addressSelect: [],
        collectAddress: '',
        county: null,
        countyId: null,
        postalCode: null,
        addressType: null,
        addressTypeName: null,
        isDefault: null
      },
      addresstype: [],
      addValueData: [],
      htbj: '',
      htds: '',
      hthddz: '',
      hthdyj: '',
      supportRateHtml: '',
      bjzd: 0,
      isDefaultTitle: false,
      duthf: '', // 短途提货费
      bjyf: '', // 保价运费
      gxyf: '', // 干线运费
      dshkf: '', // 代收货款费
      dtshf: '', // 短途送货费
      yjf: '', // 月结费
      hdf: '', // 回单费
      xxf: '', // 信息费
      fpf: '', // 发票费
      mStmHeavyRatioInterval: {}, // 获取重泡比区间
      isHeavyRatioInterval: false, // 是否重泡比区间
      iszp: false
    };
  },
  methods: {
    phoneFun (rule, value, callback) {
      if (isEmpty(this.myAddress.contactPhone) && isEmpty(this.myAddress.telephone)) {
        return callback(new Error('手机和固定电话必须填写其中一项'));
      }
      callback();
    },
    extractDateFun (rule, value, callback) {
      if (isEmpty(this.orderForm.shipmentsDate)) {
        this.orderForm.extractDate = null;
        return callback(new Error('请先选择发货时间'));
      }
      if (!isEmpty(this.orderForm.extractDate) && this.orderForm.extractDate.getTime() > this.orderForm.shipmentsDate.getTime()) {
        return callback(new Error('请选择提货时间在发货时间前'));
      }
      callback();
    },
    checkCargo (rule, value, callback) {
      if (this.isCargoShow && isEmpty(this.orderCargoForm.cargoName)) {
        return callback(new Error('请输入货品名称'));
      }
      if (!this.isCargoShow && isEmpty(this.orderCargoForm.cargoId)) {
        return callback(new Error('请选择货品名称'));
      }
      callback();
    },
    elseCargoClick () {
      this.orderCargoForm.cargoId = '';
      this.orderCargoForm.cargoName = '';
      if (this.isCargoShow) {
        this.isCargoShowText = '手输';
        this.isCargoShow = false;
      } else {
        this.isCargoShowText = '选择';
        this.isCargoShow = true;
      }
    },
    elsePackTypeClick () {
      this.orderCargoForm.packType = '';
      this.orderCargoForm.packTypeName = '';
      if (this.isPackTypeShow) {
        this.isPackTypeShowText = '手输';
        this.isPackTypeShow = false;
      } else {
        this.isPackTypeShowText = '选择';
        this.isPackTypeShow = true;
      }
    },
    addAddress () {
      let temp = '';
      this.myAddress.userId = this.orderForm.memberUserId;
      if (this.addressSelect != null) {
        this.myAddress.provinceId = this.myAddress.addressSelect[0];
        this.myAddress.cityId = this.myAddress.addressSelect[1];
        this.myAddress.countyId = this.myAddress.addressSelect[2];
      }
      if (this.addressSelect[0] !== undefined) {
        temp += this.addressSelect[0] + ',';
      }
      if (this.addressSelect[1] !== undefined) {
        temp += this.addressSelect[1] + ',';
      }
      if (this.addressSelect[2] !== undefined) {
        temp += this.addressSelect[2];
      }
      this.myAddress.collectAddress = temp;
      this.$refs['myAddress'].validate((valid) => {
        if (valid) {
          saveAddress(this.myAddress).then((res) => {
            if (res.data.successFlg) {
              this.addressDialog = false;
              this.$message.success('添加成功！');
              let f = 'addressType=' + this.myAddress.addressType + ';userId=' + this.userId + ';contactName?' + this.myAddress.contactName;
              this.searchShipmentAddresses(f, this.myAddress.addressType, res.data.obj.id);
            } else {
              this.$message.error(res.data.errorMsg);
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
        }
      });
    },
    addContacts (val) {
      this.addressSelect = [];
      if (this.$refs.myAddress) {
        this.$refs.myAddress.resetFields();
      }
      for (let p in this.myAddress) {
        if (this.myAddress[p] instanceof Array) {
          this.myAddress[p] = [];
        } else {
          this.myAddress[p] = null;
        }
      }
      this.addressDialogTitle = '添加联系人';
      this.addressDialog = true;
      this.myAddress.addressType = val.type;
      this.myAddress.addressTypeName = val.name;
    },
    addValueChange (val) {
      if (val === 'bj') {
        if (!isEmpty(this.addValues[0].value) && (this.addValues[0].value < 3000 || this.addValues[0].value > 1000000)) {
          return this.$message.error('保价金额范围在3000-1000000');
        }
      } else {
        if (!isEmpty(this.addValues[1].value) && (this.addValues[1].value < 1 || this.addValues[1].value > 50000)) {
          return this.$message.error('代收金额范围在1-50000');
        }
      }
      this.calculatePrice();
    },
    searchReservationRuleFreights (startAddressDicts, endAddressDicts) {
      searchReservationRuleFreights({
        start_address_dicts: startAddressDicts.join(','),
        end_address_dicts: endAddressDicts.join(',')
      }).then((res) => {
        res.data.detailModelList.push({
          days: 0,
          percentage: ''
        });
        for (let days in res.data.detailModelList) {
          let mr = res.data.detailModelList[days];
          let push = mr.appointDay + 1;
          var d = new Date(Date.now());
          d.setDate(d.getDate() + push - 1);
          var years = d.getFullYear();
          var months = d.getMonth();
          var day = d.getDate();
          this.shipmentsDateValuePOS.discount[new Date(years, months, day).getTime()] = '<label style="display: block;color: red;font-size: 9px;">' + mr.discountRate + '</label>';
        }
      });
    },
    searchMemberUsersChange () {
      this.orderForm.memberUserName = getSelectObect(this.orderForm.memberUserId, 'userId', this.memberUsers).realName;
      this.orderForm.sendContactName = null;
      this.orderForm.sendContactPhone = null;
      this.orderForm.sendTelephone = null;
      this.orderForm.sendStreet = null;
      this.orderForm.shipmentsContactName = null;
      this.orderForm.shipmentsContactPhone = null;
      this.orderForm.shipmentsTelephone = null;
      this.orderForm.shipmentsStreet = null;
      this.shipmentAddressesSelect = [];
      this.sendAddressSelect = [];
      this.searchTaxsheetTitle('EQ_taxsheetType=102013001;');
    },
    invoiceAddressChange (val) {
      let thisSendAddresses = this.orderForm.sendAddressSelect;
      let thisShipmentAddresses = this.orderForm.shipmentAddressesSelect;

      let inSendAddresses = this.shipmentAddressesSelectModel;
      let inShipmentAddresses = this.sendAddressSelectModel;

      if (val === 'else') {
        this.orderForm.invoiceAddressProvinceId = this.invoiceAddressSelect[0];
        this.orderForm.invoiceAddressCityId = this.invoiceAddressSelect[1];
        this.orderForm.invoiceAddressCountyId = this.invoiceAddressSelect[2];
      } else if (val === 'shipmentsAccordance') {
        if (thisSendAddresses[0] !== inSendAddresses[0] || thisSendAddresses[1] !== inSendAddresses[1] || thisSendAddresses[2] !== inSendAddresses[2]) {
          this.orderForm.invoiceAddressId = this.orderForm.shipmentsAddressId;
        } else {
          this.orderForm.invoiceAddressId = '';
        }

        this.orderForm.invoiceAddressProvinceId = this.orderForm.shipmentAddressesSelect[0];
        this.orderForm.invoiceAddressCityId = this.orderForm.shipmentAddressesSelect[1];
        this.orderForm.invoiceAddressCountyId = this.orderForm.shipmentAddressesSelect[2];
        this.orderForm.invoiceAddressStreet = this.orderForm.shipmentsStreet;
      } else {
        if (thisShipmentAddresses[0] !== inShipmentAddresses[0] || thisShipmentAddresses[1] !== inShipmentAddresses[1] || thisShipmentAddresses[2] !== inShipmentAddresses[2]) {
          this.orderForm.invoiceAddressId = this.orderForm.sendAddressId;
        } else {
          this.orderForm.invoiceAddressId = '';
        }

        this.orderForm.invoiceAddressProvinceId = this.orderForm.sendAddressSelect[0];
        this.orderForm.invoiceAddressCityId = this.orderForm.sendAddressSelect[1];
        this.orderForm.invoiceAddressCountyId = this.orderForm.sendAddressSelect[2];
        this.orderForm.invoiceAddressStreet = this.orderForm.sendStreet;
      }
    },
    searchReceiptTypeChange (val) {
      if (!isEmpty(val) && !isEmpty(val.dictVal)) {
        this.addValues[2].dictValue = val.dictVal;
        this.addValues[2].value = val.cnDictValname;
      }
      let name = '';
      if (val === '101002004') {
        name = '原件回单';
      } else {
        name = '电子回单';
      }
      this.addValues[2].dictValue = val;
      this.addValues[2].value = name;
      this.calculatePrice();
    },
    invoiceTypeChange (val) {
      let name = '';
      let type = '';
      if (val === '101002005') {
        name = '个人普通发票';
        type = 102013001;
      }
      if (val === '101002006') {
        name = '单位普通发票';
        type = 102013002;
      }
      if (val === '101002007') {
        name = '增值税发票';
        type = 102013003;
      }
      this.addValues[3].dictValue = val;
      this.addValues[3].value = name;
      this.taxsheetTitles = [];
      this.taxsheetTitle = '';
      this.searchTaxsheetTitle('EQ_taxsheetType=' + type + ';');
      this.calculatePrice();
    },
    searchextractTypeChange (val) {
      if (val === 105002002) {
        this.orderForm.extractDate = null;
        this.orderForm.extractTime = null;
      }
      this.orderForm.startNetworkManagementId = '';
      this.calculatePrice();
    },
    sendTypeTypeChange (val) {
      if (val === 105001002) {
        this.orderForm.sendTime = null;
      }
      this.orderForm.endNetworkManagementId = '';
      this.calculatePrice();
    },
    getNetworkManagements (params) {
      search(params).then((res) => {
        this.startNetworkManagements = [];
        this.endNetworkManagements = [];
        if (res.data.successFlg) {
          this.startNetworkManagements = res.data.obj.starts;
          this.endNetworkManagements = res.data.obj.ends;
        }
      });
    },
    bfcalculatePrice (val) {
      this.orderForm.paymentType = null;
      this.getPaymentTypes(val);
      this.calculatePrice(val);
    },
    changeVolumeAndWeight () {
      if (!isEmpty(this.orderCargoForm.weight) && !isEmpty(this.orderCargoForm.volume)) {
        let heavyRatioIntervalRatio = this.orderCargoForm.volume / this.orderCargoForm.weight;
        if (!isEmpty(this.mStmHeavyRatioInterval) && (this.mStmHeavyRatioInterval.minimum <= heavyRatioIntervalRatio && heavyRatioIntervalRatio <= this.mStmHeavyRatioInterval.maximum)) {
          this.iszp = true;
        } else {
          this.iszp = false;
        }
        if (!isEmpty(this.mStmHeavyRatioInterval) && (this.mStmHeavyRatioInterval.minimum <= heavyRatioIntervalRatio && heavyRatioIntervalRatio <= this.mStmHeavyRatioInterval.maximum) && this.mStmHeavyRatioInterval.isPricingExpress === 111002001) {
          this.isHeavyRatioInterval = true;
          if (this.mStmHeavyRatioInterval.isPricingExpress === 111002001) {
            this.setShipings({ageingType: 112006003});
          }
        } else {
          this.isHeavyRatioInterval = false;
          this.sendAddressSelectChange();
        }
      }
      ;
      this.calculatePrice();
    },
    calculatePrice (val) {
      let start = this.orderForm.shipmentAddressesSelect;
      let end = this.orderForm.sendAddressSelect;
      this.getNetworkManagements({
        start_province_id: start[0],
        start_city_id: start[1],
        start_county_id: start[2],
        end_province_id: end[0],
        end_city_id: end[1],
        end_county_id: end[2]
      });
      if (isEmpty(this.orderCargoForm.weight) && isEmpty(this.orderCargoForm.volume)) {
        return this.$message.error('体积和重量必须填写一项');
      }
      if (this.orderForm.agingModel.ageingType === 112006003) {
        this.lineType = 112006003;
        this.orderForm.agingName = '定价快运';
        this.orderForm.agingDictEntityId = 112006003;
        this.pricing();
      } else {
        if (isEmpty(this.lineType) && !isEmpty(val)) {
          this.lineType = val.ageingType;
        }
        this.orderPrices = [];
        this.$refs['orderCargoForm'].validate((orderCargoFormValid) => {
          if (orderCargoFormValid) {
            if (isEmpty(this.orderForm.paymentType)) {
              return this.$message.error('请选择付款方式');
            }
            this.orderForm.agingId = this.orderForm.agingModel.id;
            this.orderForm.agingName = this.orderForm.agingModel.ageingTypeName;
            this.orderForm.agingDictEntityId = this.orderForm.agingModel.ageingType;
            if (isEmpty(this.orderForm.agingModel.ageingType)) {
              return this.$message.error('请选择运输产品方式');
            }
            let insuredV = '';// 保价值
            let collectionV = '';
            let insuredProportion = '';
            let collectionProportion = '';
            let theReceiptV = '';
            let theReceiptType = isEmpty(this.addValues[2].dictValue) ? 101002003 : this.addValues[2].dictValue;
            getFreightAddValue(this.token).then((res) => {
              let AddValueData = res.data;
              if (AddValueData.successFlg) {
                for (let avd in AddValueData.detailModelList) {
                  let avdModel = AddValueData.detailModelList[avd];
                  if (avdModel.dictValue === 101002001) { // 保价比例
                    if (this.orderForm.agingDictEntityId === 112006004) {
                      if (!isEmpty(this.htbj)) {
                        insuredV = this.addValues[0].value * this.htbj;
                        insuredProportion = this.htbj;
                      } else {
                        insuredV = this.addValues[0].value * avdModel.value;
                        insuredProportion = avdModel.value;
                      }
                    } else {
                      insuredV = this.addValues[0].value * avdModel.value;
                      insuredProportion = avdModel.value;
                    }
                  } else if (avdModel.dictValue === 101002002) { // 代收货款比例
                    if (this.orderForm.agingDictEntityId === 112006004) {
                      if (!isEmpty(this.htds)) {
                        collectionV = this.addValues[0].value * this.htds;
                        collectionProportion = this.htds;
                      } else {
                        collectionV = this.addValues[1].value * avdModel.value;
                        collectionProportion = avdModel.value;
                      }
                    } else {
                      collectionV = this.addValues[1].value * avdModel.value;
                      collectionProportion = avdModel.value;
                    }
                  } else if (avdModel.dictValue === parseInt(theReceiptType)) { // 回单比例
                    if (this.orderForm.agingDictEntityId === 112006004) {
                      if (parseInt(this.receiptType) === 101002004) {
                        theReceiptV = this.hthdyj;
                      } else if (parseInt(this.receiptType) === 101002003) {
                        theReceiptV = this.hthddz;
                      }
                    } else {
                      theReceiptV = avdModel.value;
                    }
                  }
                }
                let sp = this.shippings;
                for (let i = 0; i < sp.length; i++) {
                  if (sp[i].id === this.orderForm.agingId) {
                    this.sxType = sp[i].ageingType;
                  }
                }
                // 用于参与计费的model
                let priceModel = {
                  insuredProportion: insuredProportion, // 保价比例
                  cargoType: this.orderCargoForm.cargoType, // 货物类型
                  userId: this.orderForm.memberUserId, // 用户id
                  collectionProportion: collectionProportion, // 代收货款比例
                  theReceiptProportion: theReceiptV, // 回单比例
                  insuredValue: this.addValues[0].value, // 保价
                  collectionValue: this.addValues[1].value, // 代收货款
                  insured: insuredV, // 保价*比例
                  collection: collectionV, // 代收货款*比例
                  extractType: this.orderForm.extractType, // 提货方式
                  sendType: this.orderForm.sendType, // 送货方式
                  theReceipt: theReceiptV, // 回单
                  theReceiptType: theReceiptType, // 回单类型
                  invoiceType: isEmpty(this.invoiceTypeModel) ? '' : this.addValues[3].dictValue, // 发票类型
                  typeOfShipping: this.sxType, // 运输方式
                  weight: this.orderCargoForm.weight, // 重量
                  volume: this.orderCargoForm.volume, // 体积
                  startOrderAddressId: this.orderForm.shipmentsAddressId,
                  endOrderAddressId: this.orderForm.sendAddressId,
                  isFrhtContract: this.lineType === 112006004 ? 111002001 : 111002002,
                  baseFreightId: this.orderForm.agingId, // 基础运价ID
                  percentage: this.discount, // 优惠比例
                  payWay: this.orderForm.paymentType// 付款方式
                };
                searchPrice({
                  json_model: priceModel
                }).then((res) => {
                  if (res.data.successFlg) {
                    this.orderPrice = res.data.obj;
                    this.orderPrices = this.orderForm.orderCostDetails = res.data.detailModelList;
                    getStmParamByType({
                      stmParamType: 'INSURED_MINIMUM_INSURED'
                    }).then((res) => {
                      let bjm = true;
                      for (let op in this.orderPrices) {
                        if (this.orderPrices[op].costCode === 101005005 && this.orderPrices[op].costPrice > 0) {
                          bjm = false;
                          if (this.orderPrices[op].costPrice < parseFloat(res.data.obj.stmParamVal)) {
                            this.orderPrices[op].costPrice = parseFloat(res.data.obj.stmParamVal);
                          }
                        }
                      }
                      if (bjm && !isEmpty(this.addValues[0].value)) {
                        this.orderPrices.push({
                          costCode: 101005005,
                          costName: '保价',
                          costPrice: parseFloat(res.data.obj.stmParamVal)
                        });
                      }
                    });
                    for (let orderPrice in this.orderPrices) {
                      if (!isEmpty(this.orderPrices[orderPrice].costPrice) && this.orderPrices[orderPrice].costPrice !== 0) {
                        if (this.orderPrices[orderPrice].costCode === 101005005 && this.orderPrices[orderPrice].costPrice < parseFloat(this.bjzd)) {
                          this.orderPrices[orderPrice].costPrice = this.bjzd;
                        }
                      }
                    }
                    let totalPrice = 0;
                    let fptotal = 0;
                    for (let orderPrice in this.orderPrices) {
                      let fpcode = parseFloat(this.orderPrices[orderPrice].costCode);
                      if (fpcode !== 101005009 && fpcode !== 101005010 && fpcode !== 101005011) {
                        if (!isEmpty(this.orderPrices[orderPrice].costPrice)) {
                          fptotal += parseFloat(this.orderPrices[orderPrice].costPrice);
                        }
                      }
                    }
                    for (let orderPrice in this.orderPrices) {
                      if (this.orderPrices[orderPrice].costCode === 101005009 || this.orderPrices[orderPrice].costCode === 101005010 || this.orderPrices[orderPrice].costCode === 101005011) {
                        this.orderPrices[orderPrice].costPrice = fptotal * this.orderPrices[orderPrice].calculateUnivalence;
                      }
                    }
                    for (let orderPrice in this.orderPrices) {
                      if (!isEmpty(this.orderPrices[orderPrice].costPrice) && this.orderPrices[orderPrice].costPrice !== 0) {
                        totalPrice += parseFloat(this.orderPrices[orderPrice].costPrice);
                      }
                    }
                    this.orderForm.orderPrice = totalPrice;
                    this.$message.success('费用计算成功');
                    this.showOrderCostDetail(this.orderPrices);
                  } else {
                    this.orderForm.orderPrice = 0;
                  }
                });
              }
            });
          }
        });
      }
    },
    showOrderCostDetail () {
      this.duthf = 0;
      this.bjyf = 0;
      this.gxyf = 0;
      this.dshkf = 0;
      this.dtshf = 0;
      this.yjf = 0;
      this.hdf = 0;
      this.xxf = 0;
      this.fpf = 0;
      let heavyRatioIntervalRatio = this.orderCargoForm.volume / this.orderCargoForm.weight;
      if (!isEmpty(this.mStmHeavyRatioInterval) && (this.mStmHeavyRatioInterval.minimum <= heavyRatioIntervalRatio && heavyRatioIntervalRatio <= this.mStmHeavyRatioInterval.maximum) && this.mStmHeavyRatioInterval.isPricingExpress === 111002002) {
      }
      for (let odp in this.orderPrices) {
        let os = this.orderPrices[odp];
        let pe = Math.round(os.costPrice * 100) / 100;
        if (os.costCode === 101005001) {
          this.duthf = pe; // 短途提货费
        }
        if (os.costCode === 101005005) {
          this.bjyf = pe; // 保价运费
        }
        if (os.costCode === 101005002) {
          if (this.orderForm.agingDictEntityId !== 112006003) {
            pe = pe + '  (原价 ¥ ' + Math.round((os.costPrice + this.orderPrice.preferentialLine + this.orderPrice.advanceOrder) * 100) / 100 + '提前下单优惠' + this.orderPrice.advanceOrder + '元，线路优惠' + this.orderPrice.preferentialLine + '元)';
          }
          this.gxyf = pe; // 干线运费
        }
        if (os.costCode === 101005006) {
          this.dshkf = pe; // 代收货款费
        }
        if (os.costCode === 101005003) {
          this.dtshf = pe; // 短途送货费
        }
        if (os.costCode === 101005004) {
          this.yjf = pe; // 月结费
        }
        if (os.costCode === 101005007 || os.costCode === 101005008) {
          this.hdf = pe; // 回单费
        }
        if (os.costCode === 101005014) {
          this.xxf = pe; // 信息费
        }
        if (os.costCode === 101005009 || os.costCode === 101005010 || os.costCode === 101005011) {
          this.fpf = pe; // 发票费
        }
      }
    },
    setStmHeavyRatio () {
      let data = this.mStmHeavyRatioInterval;
      if (!isEmpty(data) && data.isPricingExpress === 111002002) {
        for (let odp in this.orderPrices) {
          // 短途提货费
          if (this.orderPrices[odp].costCode === 101005001 && data.isPickUpCharge === 111002001) {
            this.orderPrices[odp].costPrice = this.orderPrices[odp].costPrice + this.orderPrices[odp].costPrice * data.priceIncreaseRatio;
          }
          // 短途送货费
          if (this.orderPrices[odp].costCode === 101005003 && data.isDeliveryCharges === 111002001) {
            this.orderPrices[odp].costPrice = this.orderPrices[odp].costPrice + this.orderPrices[odp].costPrice * data.priceIncreaseRatio;
          }
          // 干线运费
          if (this.orderPrices[odp].costCode === 101005002 && data.isTrunkFreight === 111002001) {
            this.orderPrices[odp].costPrice = parseFloat(this.orderPrices[odp].costPrice) + parseFloat(this.orderPrices[odp].costPrice) * data.priceIncreaseRatio;
          }
        }
      }
    },
    searchTaxsheetTitleRm (val) {
      let filters = 'LIKE_taxsheetTitle=' + val + ';';
      if (!isEmpty(this.invoiceTypeModel)) {
        filters += 'EQ_taxsheetType=' + this.invoiceTypeModel + ';';
      }
      this.searchTaxsheetTitle(filters);
    },
    searchTaxsheetTitle (val) {
      let filters = '';
      if (isEmpty(val)) {
        filters = 'EQ_userId=' + this.userId;
      } else {
        filters = val + 'EQ_userId=' + this.userId;
      }
      searchInvoiceManageByFilters({
        filters: filters,
        sorts: '-createDate',
        size: '15',
        page: '1'
      }).then((res) => {
        this.isTaxsheetTitlesDefault = false;
        let models = res.data.detailModelList;
        this.taxsheetTitles = models;
        for (let m in models) {
          if (models[m].isDefault === 111002001 && this.isDefaultTitle) {
            this.taxsheetTitle = models[m].id;
            if (models[m].taxsheetType === 102013001) {
              this.invoiceTypeModel = '101002005';
            }
            if (models[m].taxsheetType === 102013002) {
              this.invoiceTypeModel = '101002006';
            }
            if (models[m].taxsheetType === 102013003) {
              this.invoiceTypeModel = '101002007';
            }
            this.isTaxsheetTitlesDefault = true;
          }
        }
      });
    },
    searchTaxsheetTitleChange (val) {
      let taxsheetTitleName = getSelectObect(val, 'id', this.taxsheetTitles).taxsheetTitle;
      this.addValues[3].taxsheetTitleId = val;
      this.addValues[3].taxsheetTitle = taxsheetTitleName;
      this.orderForm.valueMessage = taxsheetTitleName;
    },
    createOrder (orderStatus, type) {
      this.orderForm.memberUserId = this.userId;
      this.orderForm.memberUserName = this.realName;
      if (isEmpty(this.orderForm.orderPrice) || this.orderForm.orderPrice <= 0) {
        return this.$message.error('订单价格为零，无法提交');
      }
      if (isEmpty(this.orderCargoForm.weight) && isEmpty(this.orderCargoForm.volume)) {
        return this.$message.error('体积和重量必须填写一项');
      }
      if (this.isDefaultTitle && (isEmpty(this.addValues[3].dictValue) || isEmpty(this.taxsheetTitle))) {
        return this.$message.error('请选择发票类型和抬头');
      }
      let isyf = true;
      for (let op in this.orderPrices) {
        if (this.orderPrices[op].costCode === 101005002) {
          isyf = false;
          if (isEmpty(this.orderPrices[op].costPrice)) {
            return this.$message.error('请输入运费');
          }
        }
      }
      if (isyf) {
        return this.$message.error('请输入运费');
      }
      if (isEmpty(this.orderForm.paymentType)) {
        return this.$message.error('请选择付款方式');
      }
      if (isEmpty(this.orderForm.agingModel.id) && isEmpty(this.orderForm.agingDictEntityId)) {
        return this.$message.error('请选择运输产品');
      }
      let backupsAddValues = this.addValues;
      if (!isEmpty(this.addValues[0].value) && (this.addValues[0].value < 3000 || this.addValues[0].value > 1000000)) {
        return this.$message.error('保价金额范围在3000-1000000');
      }
      if (!isEmpty(this.addValues[1].value) && (this.addValues[1].value < 1 || this.addValues[1].value > 50000)) {
        return this.$message.error('代收金额范围在1-50000');
      }

      if (isEmpty(this.orderForm.orderPrice) && this.orderForm.orderCostDetails.length <= 0) {
        return this.$message.error('请先预估费用');
      }
      // 表单验证
      this.$refs['orderForm'].validate((valid) => {
        if (valid) {
          this.$refs['orderCargoForm'].validate((orderCargoFormValid) => {
            if (orderCargoFormValid) {
              this.orderForm.orderDiscount = this.discount;
              this.orderForm.agingName = this.orderForm.agingModel.ageingTypeName;
              this.orderForm.orderStatus = orderStatus;
              this.orderForm.shipmentsProvinceId = this.orderForm.shipmentAddressesSelect[0];
              this.orderForm.shipmentsCityId = this.orderForm.shipmentAddressesSelect[1];
              this.orderForm.shipmentsCountyId = this.orderForm.shipmentAddressesSelect[2];
              this.orderForm.sendProvinceId = this.orderForm.sendAddressSelect[0];
              this.orderForm.sendCityId = this.orderForm.sendAddressSelect[1];
              this.orderForm.sendCountyId = this.orderForm.sendAddressSelect[2];
              if (this.orderForm.extractDate !== '' && this.orderForm.extractDate !== undefined && this.orderForm.extractDate != null) {
                this.orderForm.extractDate = new Date(this.orderForm.extractDate).Format('yyyy-MM-dd');
              }
              if (this.orderForm.sendTime !== '' && this.orderForm.sendTime !== undefined && this.orderForm.sendTime != null) {
                this.orderForm.sendTime = new Date(this.orderForm.sendTime).Format('yyyy-MM-dd');
              }
              this.orderForm.orderCostDetails = this.orderPrices;
              for (let ocd in this.orderForm.orderCostDetails) {
                if (this.orderForm.orderCostDetails[ocd].costCode === '原件回单') {
                  this.orderForm.orderCostDetails[ocd].costCode = 101002004;
                  this.orderForm.orderCostDetails[ocd].costName = '原件回单';
                }
                if (this.orderForm.orderCostDetails[ocd].costCode === '电子回单') {
                  this.orderForm.orderCostDetails[ocd].costCode = 101002003;
                  this.orderForm.orderCostDetails[ocd].costName = '电子回单';
                }
              }
              if (this.isCargoShow) {
                this.orderCargoForm.cargoId = null;
                this.orderCargoForm.cargoType = null;
              }
              if (this.isPackTypeShow) {
                this.orderCargoForm.packType = null;
              }
              this.orderForm.orderCargos[0] = this.orderCargoForm;
              this.orderForm.addValues = this.addValues;
              let ishd = true;
              for (let oad in this.orderForm.addValues) {
                if (parseInt(this.orderForm.addValues[oad].dictValue) === 101002003 || parseInt(this.orderForm.addValues[oad].dictValue) === 101002004) {
                  ishd = false;
                }
              }
              if (ishd) {
                this.orderForm.addValues.push({dictValue: 101002003, value: '电子回单'});
              }
              if (this.noticeDelivery) {
                this.orderForm.addValues.push({dictValue: 101002009, value: '等通知放货'});
                this.orderForm.noticeDeliveryStatus = 101022002;
              } else {
                this.orderForm.noticeDeliveryStatus = 101022001;
              }
              this.orderForm.preferentialLine = this.orderPrice.preferentialLine;
              this.orderForm.advanceOrder = this.orderPrice.advanceOrder;
              // 移除空的
              saveOrder(this.token, this.orderForm).then((res) => {
                if (res.data.successFlg) {
                  if (type === 'saveAndReset' && res.data.successFlg) {
                    this.$message.success('保存成功');
                    setTimeout(() => {
                      this.resetOrderForm();
                    }, 1000);
                  }
                  this.$message.success('保存成功');
                  this.orderForm.orderNumber = res.data.obj.orderNumber;
                  this.orderForm.orderSourceName = res.data.obj.orderSourceName;
                  this.orderForm.orderStatusName = res.data.obj.orderStatusName;
                  this.orderForm.mMebPersonal.partnerName = res.data.obj.mMebPersonal.partnerName;
                  this.orderForm.organizationModel.name = res.data.obj.organizationName;
                  this.orderForm.createDate = res.data.obj.createDate;
                } else {
                  this.$message.error(res.data.errorMsg);
                }

                this.addValues = backupsAddValues;
              });
            }
          });
        }
      });
    },
    searchMemberUsers (val) {
      let filters = isEmpty(val) ? 'logicStatus=111002002;status=111002001' : 'logicStatus=111002002;status=111002001;realName?' + val + ' g1';
      getMemberUsers({
        token: this.token,
        filters: filters,
        sorts: '+createDate',
        size: '15',
        page: '1'
      }).then((res) => {
        this.memberUsers = res.data.detailModelList;
      });
    },
    searchextractTypes (dictCodeId) {
      getDictEntityByDictCode({token: this.token, dictCode: dictCodeId}).then((res) => {
        if (dictCodeId === 105002) {
          this.extractTypes = res.data.detailModelList;
        } else {
          this.sendTypes = res.data.detailModelList;
        }
      });
    },
    sshipmentAddresses (val) {
      let f = 'addressType=109002002;userId=' + this.userId;
      let filters = isEmpty(val) ? f : f + ';contactName?' + val;
      if (!isEmpty(this.userId)) {
        this.searchShipmentAddresses(filters, 109002002);
      }
    },
    ssendAddresses (val) {
      let f = 'addressType=109002001;userId=' + this.userId;
      let filters = isEmpty(val) ? f : f + ';contactName?' + val;
      if (!isEmpty(this.userId)) {
        this.searchShipmentAddresses(filters, 109002001);
      }
    },
    searchShipmentAddresses (filters, addressTypeId, addressId) {
      getAddresses({
        token: this.token,
        filters: filters,
        sorts: '',
        size: '15',
        page: '1'
      }).then((res) => {
        if (addressTypeId === 109002002) {
          this.shipmentAddresses = res.data.detailModelList;
          if (!isEmpty(addressId)) {
            for (let sa in this.shipmentAddresses) {
              if (this.shipmentAddresses[sa].id === addressId) {
                this.orderForm.shipmentsContactName = addressId;
                break;
              }
            }
          }
        } else {
          this.sendAddresses = res.data.detailModelList;
          if (!isEmpty(addressId)) {
            for (let sa in this.sendAddresses) {
              if (this.sendAddresses[sa].id === addressId) {
                this.orderForm.sendContactName = addressId;
                break;
              }
            }
          }
        }
      });
    },
    shipmentsContactNameChange (val) {
      let shipmentData = null;
      let shipmentAddresses = this.shipmentAddresses;
      for (let i = 0; i < shipmentAddresses.length; i++) {
        if (shipmentAddresses[i].id === val) {
          shipmentData = shipmentAddresses[i];
          this.orderForm.shipmentsAddressId = this.shipmentAddressesSelectid = shipmentData.id;
          this.orderForm.shipmentsContactName = shipmentData.contactName;
          this.orderForm.shipmentsContactPhone = shipmentData.contactPhone;
          this.orderForm.shipmentsTelephone = shipmentData.telephone;
          this.orderForm.shipmentsStreet = shipmentData.street;
          this.orderForm.shipmentAddressesSelect = [shipmentData.provinceId, shipmentData.cityId, shipmentData.countyId];
          this.shipmentAddressesSelectModel = [shipmentData.provinceId, shipmentData.cityId, shipmentData.countyId];
        }
      }
      this.orderForm.startNetworkManagementId = '';
      this.sendAddressSelectChange();
    },
    sendContactNameChange (val) {
      let sendData = null;
      let sendAddresses = this.sendAddresses;
      for (let i = 0; i < sendAddresses.length; i++) {
        if (sendAddresses[i].id === val) {
          sendData = sendAddresses[i];
          this.orderForm.sendAddressId = this.sendAddressSelectId = sendData.id;
          this.orderForm.sendContactName = sendData.contactName;
          this.orderForm.sendContactPhone = sendData.contactPhone;
          this.orderForm.sendTelephone = sendData.telephone;
          this.orderForm.sendStreet = sendData.street;
          this.orderForm.sendAddressSelect = [sendData.provinceId, sendData.cityId, sendData.countyId];
          this.sendAddressSelectModel = [sendData.provinceId, sendData.cityId, sendData.countyId];
        }
      }
      this.orderForm.endNetworkManagementId = '';
      this.sendAddressSelectChange();
    },
    searchItemNames () {
      getItemNames({
        token: this.token,
        filters: 'status=111002001',
        sorts: '',
        size: '50',
        page: '1'
      }).then((res) => {
        this.cargoNames = res.data.detailModelList;
      });
    },
    cargoNameChange (val) {
      let cargoName = null;
      let cargoNames = this.cargoNames;
      for (let i = 0; i < cargoNames.length; i++) {
        if (cargoNames[i].id === val) {
          cargoName = cargoNames[i];
        }
      }
      this.orderCargoForm.cargoTypeName = cargoName.typeModel.cnDictValname;
      this.orderCargoForm.cargoType = cargoName.type;
      this.orderCargoForm.cargoId = val;
      this.orderCargoForm.cargoName = cargoName.name;
    },
    packTypeChanges (val) {
      let packTypeName = null;
      let packTypes = this.packTypes;
      for (let i = 0; i < packTypes.length; i++) {
        if (packTypes[i].dictVal === val) {
          packTypeName = packTypes[i];
        }
      }
      if (!isEmpty(packTypeName)) {
        this.orderCargoForm.packTypeName = packTypeName.cnDictValname;
      }
    },
    searchPackTypes () {
      getDictEntityByDictCode({token: this.token, dictCode: 109001}).then((res) => {
        this.packTypes = res.data.detailModelList;
      });
    },
    searchInvoiceTypes () {
      let filters = 'dictVal=101002005,101002006,101002007';
      getDictEntity({token: this.token, filters: filters}).then((res) => {
        this.invoiceTypes = res.data.detailModelList;
      });
    },
    searchReceiptTypes (val) {
      let filters = 'dictVal=101002003,101002004';
      getDictEntity({token: this.token, filters: filters}).then((res) => {
        this.receiptTypes = res.data.detailModelList;
      });
    },
    sendAddressSelectChange (val) {
      if (val === 'sendAddress') {
        this.orderForm.endNetworkManagementId = '';
      }
      if (val === 'shipmentAddress') {
        this.orderForm.startNetworkManagementId = '';
      }
      let shipmentAddressesSelectModel = this.shipmentAddressesSelectModel;
      let sendAddressSelectModel = this.sendAddressSelectModel;
      let shipmentAddressesModel = this.orderForm.shipmentAddressesSelect;
      let sendAddressModel = this.orderForm.sendAddressSelect;
      this.getNetworkManagements({
        start_province_id: shipmentAddressesModel[0],
        start_city_id: shipmentAddressesModel[1],
        start_county_id: shipmentAddressesModel[2],
        end_province_id: sendAddressModel[0],
        end_city_id: sendAddressModel[1],
        end_county_id: sendAddressModel[2]
      });
      this.orderForm.shipmentsAddressId = this.shipmentAddressesSelectid;
      this.orderForm.sendAddressId = this.sendAddressSelectId;
      if (val === 'shipmentAddress' && (shipmentAddressesSelectModel[0] !== shipmentAddressesModel[0] || shipmentAddressesSelectModel[1] !== shipmentAddressesModel[1] || shipmentAddressesSelectModel[2] !== shipmentAddressesModel[2])) {
        this.orderForm.shipmentsAddressId = '';
      } else if (val === 'sendAddress' && (sendAddressSelectModel[0] !== sendAddressModel[0] || sendAddressSelectModel[1] !== sendAddressModel[1] || sendAddressSelectModel[2] !== sendAddressModel[2])) {
        this.orderForm.sendAddressId = '';
      }
      if (isEmpty(shipmentAddressesModel[2])) {
        return;
      }
      if (isEmpty(sendAddressModel[2])) {
        return;
      }
      this.searchReservationRuleFreights(shipmentAddressesModel, sendAddressModel);
      this.shippings = [];
      searchLine({
        userId: this.orderForm.memberUserId,
        startOrderAddressId: this.orderForm.shipmentsAddressId,
        endOrderAddressId: this.orderForm.sendAddressId
      }).then((res) => {
        this.lineType = 0;
        this.orderForm.agingModel = '';
        if (res.data.successFlg) {
          let model = res.data;
          this.inds = false;
          this.hdds = false;
          /**
             * 合同快运
             */
          if (!isEmpty(model.obj) && model.obj.isFrhtContract === 111002001) {
            this.fbtitleds = true;
            this.addValues[3].taxsheetTitleId = model.obj.taxsheetTitleId;
            this.addValues[3].value = model.obj.invoiceName;
            this.orderForm.valueMessage = model.obj.taxsheetTitleName;
            this.paymentTypes = [];
            if (!isEmpty(model.obj.receipt)) {
              this.hdds = true;
              this.addValues[2].dictValue = model.obj.receipt.toString();
              this.receiptType = model.obj.receipt.toString();
            }
            if (!isEmpty(model.obj.invoice)) {
              this.inds = true;
              let newInvoice = '101002005';
              if (model.obj.invoice === 102013001) {
                newInvoice = '101002005';
              }
              if (model.obj.invoice === 102013002) {
                newInvoice = '101002006';
              }
              if (model.obj.invoice === 102013003) {
                newInvoice = '101002007';
              }
              this.addValues[3].dictValue = newInvoice;
              this.invoiceTypeModel = newInvoice;
            }
            model.obj.ageingType = 112006004;
            model.obj.ageingTypeName = '合同快运';
            this.shippings = [model.obj];
            this.freightContract = res.data.obj;
            this.orderForm.agingDictEntityId = 112006004;
            this.lineType = 112006004;
            this.setContractAddValues(this.freightContract);
            this.orderForm.paymentType = model.obj.paymentType;
            this.orderForm.agingModel = this.shippings[0];
          } else {
            // 非合同
            this.orderForm.agingDictEntityId = 0;
            this.inds = false;
            this.fbtitleds = false;
            this.addvalues();
            this.searchTaxsheetTitle('EQ_taxsheetType=102013001;');
            this.lineType = 111002002;
            if (!isEmpty(model.detailModelList)) {
              this.shippings = model.detailModelList;
            }
            this.shippings.push({ageingType: 112006003, ageingTypeName: '定价快运'});
            let heavyRatioIntervalRatio = this.orderCargoForm.volume / this.orderCargoForm.weight;
            if (!isEmpty(this.mStmHeavyRatioInterval) && (this.mStmHeavyRatioInterval.minimum <= heavyRatioIntervalRatio && heavyRatioIntervalRatio <= this.mStmHeavyRatioInterval.maximum) && this.mStmHeavyRatioInterval.isPricingExpress === 111002001) {
              this.setShipings({ageingType: 112006003});
            }
          }
        } else {
          // if (this.mStmHeavyRatioInterval.isPricingExpress === 111002001) {
          this.setShipings({ageingType: 112006003});
          // }
        }
      });
      this.orderForm.orderPrice = 0;
    },
    setShipings (o) {
      if (o.ageingType === 112006003) {
        this.shippings = [];
        this.shippings.push({ageingType: 112006003, ageingTypeName: '定价快运'});
      }
    },
    pricing () {
      this.orderPrices = [];
      if (!isEmpty(this.addValues[0].value)) { // 保价比例
        let bjv = this.addValues[0].value * this.figure(this.addValues[0].dictValue).value;
        if (bjv < parseFloat(this.bjzd)) {
          bjv = parseFloat(this.bjzd);
        }
        this.orderPrices.push({
          costCode: 101005005,
          costName: '保价',
          costPrice: bjv
        });
      }
      if (!isEmpty(this.addValues[1].value)) { // 代收货款比例
        this.orderPrices.push({
          costCode: 101005006,
          costName: '代收货款',
          costPrice: this.addValues[1].value * this.figure(this.addValues[1].dictValue).value
        });
      }

      let hdm = 0;
      let hdmv = 0;
      let name = '';
      if (!isEmpty(this.addValues[2].value)) { // 回单比例
        hdm = this.addValues[2].value;
        hdmv = this.figure(this.addValues[2].dictValue).value;
      } else {
        hdm = 101002003;
        hdmv = this.figure(hdm).value;
      }
      if (hdm === 101002003) {
        hdm = 101005007;
        name = '电子回单';
      } else {
        hdm = 101005008;
        name = '原件回单';
      }
      this.orderPrices.push({
        costCode: hdm,
        costName: name,
        costPrice: hdmv
      });

      if (!isEmpty(this.freightPrice)) {
        this.orderPrices.push({costCode: 101005002, costName: '干线运费', costPrice: this.freightPrice});
      }
      if (!isEmpty(this.freightMsgPrice)) {
        this.orderPrices.push({costCode: 101005014, costName: '信息服务费', costPrice: this.freightMsgPrice});
      }
      if (!isEmpty(this.addValues[3].value && this.orderForm.agingDictEntityId !== 112006003)) { // 发票比例
        let sum = 0;
        for (let op in this.orderPrices) {
          if (!isEmpty(this.orderPrices[op].costPrice)) {
            sum += this.orderPrices[op].costPrice;
          }
        }
        console.log(sum);
      }
      let totalPrice = 0;
      for (let orderPrice in this.orderPrices) {
        if (!isEmpty(this.orderPrices[orderPrice].costPrice)) {
          totalPrice += parseFloat(this.orderPrices[orderPrice].costPrice);
        }
      }
      this.orderForm.orderPrice = totalPrice;
      this.showOrderCostDetail();
    },
    figure (dictValue) {
      let data = {};
      for (let avd in this.addValueData) {
        if (this.addValueData[avd].dictValue === parseInt(dictValue)) {
          data = this.addValueData[avd];
          break;
        }
      }
      return data;
    },
    /**
       * 设置合同运价费率
       * @param con
       */
    setContractAddValues (con) {
      let newAddValues = [];
      let supportRatio = con.supportRatio;
      if (isEmpty(supportRatio)) {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002001) {
            supportRatio = this.addValueData[oa].value;
            this.htbj = supportRatio;
            break;
          }
        }
      }
      newAddValues.push({dictValue: 101002001, value: supportRatio});
      let collectRatio = con.collectRatio;
      if (isEmpty(collectRatio)) {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002002) {
            collectRatio = this.addValueData[oa].value;
            this.htds = collectRatio;
            break;
          }
        }
      }
      newAddValues.push({dictValue: 101002002, value: collectRatio});
      if (isEmpty(con.receipt)) {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002003) {
            newAddValues.push({dictValue: 101002003, value: this.addValueData[oa].value});
            continue;
          }
          /**
             * 原件回单
             */
          if (this.addValueData[oa].dictValue === 101002004) {
            newAddValues.push({dictValue: 101002004, value: this.addValueData[oa].value});
            continue;
          }
        }
      } else {
        if (con.receipt === 101002003) {
          this.hthddz = con.receiptValue;
        } else if (con.receipt === 101002004) {
          this.hthdyj = con.receiptValue;
        }
        newAddValues.push({dictValue: con.receipt, value: con.receiptValue});
      }
      /**
         * 设置发票费率
         */
      if (!isEmpty(con.invoice)) {
        let newInvoice = 101002005;
        if (con.invoice === 102013001) {
          newInvoice = 101002005;
        }
        if (con.invoice === 102013002) {
          newInvoice = 101002006;
        }
        if (con.invoice === 102013003) {
          newInvoice = 101002007;
        }
        newAddValues.push({dictValue: newInvoice, value: con.invoiceRatio});
      } else {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002005) {
            newAddValues.push({dictValue: 101002005, value: this.addValueData[oa].value});
            continue;
          }
          /**
             * 单位普通发票
             */
          if (this.addValueData[oa].dictValue === 101002006) {
            newAddValues.push({dictValue: 101002006, value: this.addValueData[oa].value});
            continue;
          }
          /**
             * 增值税发票
             */
          if (this.addValueData[oa].dictValue === 101002007) {
            newAddValues.push({dictValue: 101002007, value: this.addValueData[oa].value});
            continue;
          }
        }
      }
      //
      this.addValueData = [];
      this.addValueData = this.addValueDatav2 = newAddValues;
    },
    addvalues () {
      getFreightAddValue(this.token).then((res) => {
        this.addValueData = res.data.detailModelList;
      });
    },
    resetOrderForm () {
      location.reload();
    },
    getStmParamByType () {
      getStmParamByType({
        stmParamType: 'INSURED_MINIMUM_INSURED'
      }).then((res) => {
        this.bjzd = res.data.obj.stmParamVal;
        this.supportRateHtml = '保价声明金额不低于3千，不高于100万,保价费最低金额 ' + this.bjzd + ' 元';
      });
    },
    getWhetherCompulsoryTaxsheet () {
      getStmParamByType({
        stmParamType: 'WHETHER_COMPULSORY_TAXSHEET'
      }).then((res) => {
        if (!isEmpty(res.data.obj) && parseInt(res.data.obj.stmParamVal) === 111002001) {
          this.isDefaultTitle = true;
        } else {
          this.isDefaultTitle = false;
        }
      });
    },
    /**
       * 获取重泡比区间
       */
    searchStmHeavyRatio () {
      getStmHeavyRatio().then((res) => {
        if (res.data.successFlg) {
          this.mStmHeavyRatioInterval = res.data.obj;
        }
      });
    },
    /**
       * 获取付款方式
       */
    getPaymentTypes (val) {
      let filters = '';
      if (val.ageingType === 112006003) {
        filters = 'EQ_isEnable=true;EQ_isShow=true;';
      } else if (val.ageingType === 112006004) {
        this.paymentTypes = [{payWay: val.paymentType, payWayName: val.paymentTypeName}];
        return;
      } else {
        filters = 'IN_payWay=' + val.payWays.join(',');
      }
      this.paymentTypesFun(filters, data => {
        this.paymentTypes = data;
      });
    },
    paymentTypesFun (filters, fun) {
      searchALLPayWayConfig({
        filters: filters,
        sorts: ''
      }).then((res) => {
        if (res.data.successFlg) {
          return fun(res.data.detailModelList);
        } else {
          this.$message.error(res.data.errorMsg);
        }
      });
    }
  },
  mounted () {
    this.sshipmentAddresses();
    this.ssendAddresses();
    this.searchStmHeavyRatio();
    this.searchMemberUsers();
    this.getStmParamByType();
    this.getWhetherCompulsoryTaxsheet();
    this.addvalues();
    this.searchItemNames();
    this.searchReceiptTypes();
    this.searchInvoiceTypes();
    searchDictEntitys('109002').then((res) => {
      if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
        this.addresstype = res.data.detailModelList;
      }
    });
  },
  computed: {
    discountText: function () {
      let self = this;
      if (isEmpty(this.lineType) || this.lineType === 111002001) {
        return '';
      }
      if (this.orderForm.shipmentsDate) {
        self.discount = this.shipmentsDateValuePOS.discount[this.orderForm.shipmentsDate.getTime()];
        if (isEmpty(this.discount)) {
          self.discount = '';
          return '';
        }
        let doms = this.discount.split('0.');
        if (doms.length === 1) {
          self.discount = '';
          return '';
        }
        self.discount = '0.' + doms[1].replace('</label>', '');
        return this.shipmentsDateValuePOS.discount[this.orderForm.shipmentsDate.getTime()];
      } else {
        return '';
      }
    }
  }

}
;
</script>
